package com.rural.bus.model;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;
import android.view.View;

public class Order implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/***
	 * 马上用车
	 */
	public static final int ORDERTYPE_ATONCE=0;
	/***
	 * 预约用车
	 */
	public static final int ORDERTYPE_SUBSCRIBE=1;
	/***
	 * 日租
	 */
	public static final int ORDERTYPE_RENT=3;
	/***
	 * 专线
	 */
	public static final int ORDERTYPE_SPEC=4;
	
	/***
	 *新订单
	 */
	public static final int ORDERSTATUS_NEW=0;
	/***
	 * 已接单
	 */
	public static final int ORDERSTATUS_RECEIVED=1;
	/***
	 * 已就绪
	 */
	public static final int ORDERSTATUS_READYED=2;

	/***
	 * 已出发
	 */
	public static final int ORDERSTATUS_DEPARTED=3;
	/***
	 * 已到达
	 */
	public static final int ORDERSTATUS_REACHED=5;
	/***
	 *已完成
	 */
	public static final int ORDERSTATUS_COMPLETEED=6;
	/***
	 * 已取消
	 */
	public static final int ORDERSTATUS_CANCELED=4;
	
	public int orderId;

    public int driverId;

    public int userId;

    public int orderType;

    public String driverName;

    public String userName;

    public double startLongtitude;

    public double startLatitude;

    public String startLocation;

    public long takeTime;

    public String payId;

    public int payStatus;

    public double perDistance;

    public double distance;

    public int groupId;

    public String userPhone;

    public String driverPhone;

    public double finalPrice;
    
    public double estimatePrice;

    public int orderStatus;

    public int number;

    public int carType;

    public double endLatitude;

    public double endLongtitude;

    public String endLocation;

    public String remarks;

    public long createTime;
    
    public static Order parse(JSONObject object){
    	Order order=new Order();
    	try {
        	order.orderId = object.getInt("orderId");
			order.startLocation = object.getString("startLocation");
			order.userId = object.getInt("userId");
			order.userName = object.getString("userName");
			order.takeTime = object.getLong("takeTime");
			order.endLocation = object.getString("endLocation");
			order.orderType = object.getInt("orderType");
			order.number = object.getInt("number");
			order.carType = object.getInt("carType");
			order.orderStatus=object.getInt("orderStatus");
			order.driverId=object.getInt("driverId");
			order.driverPhone=object.getString("driverPhone");
			order.userPhone=object.getString("userPhone");
			order.driverName=object.getString("driverName");
			order.distance=object.getDouble("distance");
			order.estimatePrice=object.getDouble("estimatePrice");
			order.finalPrice=object.getDouble("finalPrice");
			order.remarks=object.getString("remarks");

		} catch (JSONException e) {
			e.printStackTrace();
		}
    	return order;
    }
    
    public String getOrderType(){
    	    if(orderType==ORDERTYPE_ATONCE){
    	    	    return "马上用车";
    	    }else if(orderType==ORDERTYPE_RENT){
    	    	    return "日租";
    	    }else if(orderType==ORDERTYPE_SPEC){
    	    	    return "专线";
    	    }else{
    	    	    return "预约用车";
    	    }
    }
    
    public String getOrderStatus(){
    	     String status=null;
    	     switch (orderStatus) {
			case ORDERSTATUS_NEW:
				status="未接单";
				break;

			case ORDERSTATUS_RECEIVED:
				status="已接单";
				break;
				 
			case ORDERSTATUS_READYED:
				status="已就绪";
				break;
			case ORDERSTATUS_DEPARTED:
				status="已出发";
				break;
			case ORDERSTATUS_CANCELED:
				status="已取消";
				break;
			case ORDERSTATUS_COMPLETEED:
				status="已完成";
				break;
			case ORDERSTATUS_REACHED:
				status="已到达";
				break;
			}
    	     return status;
    }
    
    /***
     * 得到车类型
     * @return
     */
    public String getCarType(){
    	if(carType==0){
    		return "经济类型";
    	}else if(carType==1){
    		return "舒服类型";
    	}else if(carType==2){
    		return "商务类型";
    	}else{
    		return "豪华类型";
    	}
    }

}
